
package br.com.trabalho.controller;

import br.com.trabalho.banco.Transacoes;
import br.com.trabalho.entidades.Receita;
import br.com.trabalho.util.Util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/receitas")
public class Receitas extends HttpServlet{
    private static final long serialVersionUID = 5131813494550532458L;
    
    protected void processa(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String url = "receitas.jsp";
        
        List<Receita> receitas = Transacoes.buscaReceitaCategoria(request.getParameter("categoria"));
        
        session.setAttribute("RECEITA_A_EXIBIR", receitas);        
        
        RequestDispatcher disp = request.getRequestDispatcher(url);
        disp.forward(request, response);              
    }    

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        processa(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        processa(request, response);
    }
    
}
